<?php

/**
 * TestBlock form.
 *
 * @package    tests
 * @subpackage form
 * @author     Djul
 */
class TestBlockForm extends BaseTestBlockForm
{
  public function configure()
  {
    $c = new criteria();
    if(!sfContext::getInstance()->getUser()->getGuardUser()->getIsSuperAdmin())
    {
        $c->addJoin(SubjectPeer::ID, UserSubjectPeer::SUBJECT_ID);
        $c->addJoin(UserSubjectPeer::USER_ID, sfContext::getInstance()->getUser()->getGuardUser()->getId());
    }
    $this->widgetSchema['subject_id'] = new sfWidgetFormPropelChoice(array('model' => 'Subject', 'add_empty' => false, 'criteria' => $c));
    $this->validatorSchema['subject_id'] = new sfValidatorPropelChoice(array('model' => 'Subject', 'column' => 'id', 'criteria' => $c));

    $this->validatorSchema->setPostValidator(
      new sfValidatorPropelUnique(array('model' => 'TestBlock', 'column' => array('name', 'subject_id')),array('invalid'=>'Назва тесту і предмету повинні бути унікальні.'))
    );
  }
}
